using System;
using Microsoft.BizTalk.ExplorerOM;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace BizTalk.BuildGenerator.Tasks
{
    /// <summary>
    /// This is a base class for tasks which want to use the BtsCatalog
    /// </summary>
    public class BtsCatalogExplorerTask : Task, IDisposable
    {
        #region Fields

        /// <summary>
        /// The connection string to the message box
        /// </summary>
        private string _MessageBoxConnection;

        /// <summary>
        /// The application name we want to work with
        /// </summary>
        private string _ApplicationName;

        /// <summary>
        /// The reference to the catalog
        /// </summary>
        private BtsCatalogExplorer _Catalog = new BtsCatalogExplorer();

        #endregion

        /// <summary>
        /// Overrides the exewcute method
        /// </summary>
        /// <returns></returns>
        public override bool Execute()
        {
            return true;
        }

        #region Properties

        /// <summary>
        /// The catalog
        /// </summary>
        protected BtsCatalogExplorer Catalog
        {
            get { return _Catalog; }
            set { _Catalog = value; }
        }

        /// <summary>
        /// This is the optional application name that msbuild can provide
        /// </summary>
        public string ApplicationName
        {
            get { return _ApplicationName; }
            set { _ApplicationName = value; }
        }

        /// <summary>
        /// This is the connection string for the message box that should be supplied by the msbuild file
        /// </summary>
        [Required]
        public string MessageBoxConnection
        {
            get { return _MessageBoxConnection; }
            set { _MessageBoxConnection = value; }
        }

        #endregion

        /// <summary>
        /// Disposable implementation
        /// </summary>
        /// <param name="canDispose"></param>
        protected virtual void Dispose(bool canDispose)
        {
            if (canDispose)
            {
                _Catalog.Dispose();
                GC.SuppressFinalize(this);
            }
        }

        #region IDisposable Members

        /// <summary>
        /// Implemented to adhere to code analysis
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
        }

        #endregion
    }
}